Title: How to Customise the WooCommerce Address Format

Publish Date: Thu, 01 Nov 2018 08:00:41 +0000

Categories: Uncategorized

Content:

Each country has a different localized format. For example, the U.S. uses the short state name, while Australia usually shows the full name.



The WooCommerce address format reflects these standards, although they are not rules set in stone, and they can always be changed.









Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:



/**
 * @snippet       Customize Address Format
 * @author        Nicola Mustone
 * @author_url    https://nicolamustone.blog/2018/11/01/how-to-customise-the-address-format-in-woocommerce/
 * @tested-up-to  WooCommerce 8.4.X
 */
add_filter( 'woocommerce_localisation_address_formats', 'nm_change_us_address_format' );
function nm_change_us_address_format( $formats ) {
	$formats['US'] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state} {postcode}\n{country}";

	return $formats;
}



This code modifies the display of addresses in the United States by replacing the state code with the full state name. For example, an address would show "California" instead of "CA".





Default WooCommerce Format



Nicola Mustone937 South Green St.Fresno, CA 93722





Custom Format



Nicola Mustone937 South Green St.Fresno, California 93722





Formatting Options



In the code, you can see some placeholders, like {name}  or {state}, but there are many of these that you can use in your WooCommerce localized address.



Here is a complete list:




{first_name}



{last_name}



{name}



{company}



{address_1}



{address_2}



{city}﻿



{state}



{postcode}



{country}



{first_name_upper}



{last_name_upper}



{name_upper}



{company_upper}



{address_1_upper}



{address_2_upper}



{city_upper}



{state_upper} 



{state_code}



{postcode_upper} 



{country_upper}




If you are selling in limited countries or regions, changing the address format is a great idea. You can show only the locations that matter to you!
